  <?php
 include ("../JO_01_configuration.php");
 $JO_MySQL = new mysqli( $JO_DB_host, $JO_DB_user, $JO_DB_password, $JO_DB_database );
 $JO_MySQL -> query( "SET NAMES 'UTF8'" );
   
	  include_once('../JO_02_function.php');
  		$loai=$_GET['SO_loai'];
		
		
  ?>

  <table class="tbi" width ="100%" style="background:">
          <tr style="">
            <th >Số điện thoại </th>
            <th >Số Lần Nhắn </th>
            <th <?=($loai=='num')?"style='background:#000'":''?>>Đầu số </th>
            <th <?=($loai=='id')?"style='background:#000'":''?>>Mã dịch vụ </th>
            <th >Nội dung yêu cầu </th>
            <th <?=($loai=='tel')?"style='background:#000'":''?>>Nhà Mạng</th>
            <th <?=($loai=='day')?"style='background:#000'":''?>>Ngày giờ </th >
          </tr>
         <?php 
				if($loai=="day")
					{
						$results='';
						$sea=$_GET['SO_sea'];
						$sea2=$_GET['SO_sea2'];
						$sea3=$_GET['SO_sea3'];
						$sea4=$_GET['SO_sea4'];
						if($sea3=='VDC'){
						$SQL="SELECT * FROM sms WHERE (sms.requesttime BETWEEN '$sea' AND '$sea2') and cmdcode like '%".$sea4."%';";
						}
						else{
						$SQL="SELECT * FROM mo_incom WHERE (mo_incom.insert BETWEEN '$sea' AND '$sea2') and command_code like '%".$sea4."%';";
						}
						
						$results=JO_query($SQL);
						$total=$results->num_rows;
						$page=1;
						$limit=50;
						if(($total%$limit)!=0) {$numpages=(int)($total/$limit)+1;}
						else                {$numpages=$total/$limit;}
						if(isset ($_REQUEST["Page"])){$page=$_REQUEST["Page"];}
						$vt=(($page-1)*$limit)+1;
					
						$result=JO_14_getday($sea,$sea2,$vt,$limit,$sea3,$sea4);
						
					}
				else
					{
						
						$sea=$_GET['SO_sea'];
						$sea2=$_GET['SO_sea2'];
						if($sea2=="VDC"){
						if($loai=='id'){
						$sql="SELECT * FROM sms WHERE cmdcode LIKE '%$sea%' ORDER BY moid;";}
						if($loai=='num'){
						$sql="SELECT * FROM sms WHERE src LIKE '%$sea%' ORDER BY moid;";}
						if($loai=='tel'){
						$sql="SELECT * FROM sms WHERE opid LIKE '%$sea%' ORDER BY moid;";}
						}
						else{
						if($loai=='id'){
						$sql="SELECT * FROM mo_incom WHERE command_code LIKE '%$sea%' ORDER BY request_id;";}
						if($loai=='num'){
						$sql="SELECT * FROM mo_incom WHERE service_id LIKE '%$sea%' ORDER BY request_id;";}
						if($loai=='tel'){
						$sql="SELECT * FROM mo_incom WHERE telco LIKE '%$sea%' ORDER BY request_id;";	}
						
						}
						$results=JO_query($sql);
						$total=$results->num_rows;
						$page=1;
						$limit=50;
						if(($total%$limit)!=0) {$numpages=(int)($total/$limit)+1;}
						else                {$numpages=$total/$limit;}
						if(isset ($_REQUEST["Page"])){$page=$_REQUEST["Page"];}
						$vt=(($page-1)*$limit)+1;
						$result=JO_14_search_pagelist($loai,$sea,$vt,$limit,$_GET['SO_sea2']);
					}
					if($result->num_rows)
					while($row=$result->fetch_array())
					{
						if($loai!="day"){
							?>
          <tr>
            <td ><?=($_GET['SO_sea2']=='VDC')?$row['dest']:$row['user_id']?></td>
            <td style="width:10px"><?=($_GET['SO_sea2']=='VDC')?$row['count']:$row['count']?></td>
            <td ><?=($_GET['SO_sea2']=='VDC')?$row['src']:$row['service_id']?></td>
            <td ><?=($_GET['SO_sea2']=='VDC')?$row['cmdcode']:$row['command_code']?></td>
            <td ><?=($_GET['SO_sea2']=='VDC')?$row['msgbody']:$row['info']?></td>
            <td ><?=($_GET['SO_sea2']=='VDC')?$row['opid']:$row['telco']?></td>
            <td ><?=($_GET['SO_sea2']=='VDC')?$row['requesttime']:$row['insert']?></td>
          </tr>
          <?php  }else{?>
          <tr>
			<td ><?=($_GET['SO_sea3']=='VDC')?$row['dest']:$row['user_id']?></td>
            <td style="width:10px"><?=($_GET['SO_sea3']=='VDC')?$row['count']:$row['count']?></td>
            <td ><?=($_GET['SO_sea3']=='VDC')?$row['src']:$row['service_id']?></td>
            <td ><?=($_GET['SO_sea3']=='VDC')?$row['cmdcode']:$row['command_code']?></td>
            <td ><?=($_GET['SO_sea3']=='VDC')?$row['msgbody']:$row['info']?></td>
            <td ><?=($_GET['SO_sea3']=='VDC')?$row['opid']:$row['telco']?></td>
            <td ><?=($_GET['SO_sea3']=='VDC')?$row['requesttime']:$row['insert']?></td>
            </tr>
			  
			  <?php }} ?>
              <tr>
              	<td colspan="6">
                Tổng Cộng:
                </td>
                <td>
                <?=$total." Tin Nhắn"?>
                </td>
              </tr>
              <?php if($total>50){  ?>
          <tr>
          			<td colspan="6" class="paging_row">
							<?

               		 if($numpages>1){
                    if($page>2){
                    ?>
              <a href="#" class='JO_pagesi' onclick="tuyen_du_lieu('1')">◀</a>
              <?
                    }
                    if($page>1){
                    ?>
              <a href="#" class='JO_pagesi' onclick="tuyen_du_lieu('<?=($page-1)?>');">◁</a>
              <?
                    }
                    if($page-4>1) echo "...";
                    for($i=$page-4;$i<=($page-1);$i++){
                        if($i>0){
                        ?>
              <a href="#" class='JO_pagesi' onclick="tuyen_du_lieu('<?=$i?>');">
              <?=$i?>
              </a>
              <?
                        }
                    }
                    echo  "<b style='color=#ffffff;' class='JO_pagesi pageactive'>".$page."</b>";
                    for($i=$page+1;$i<=($page+4);$i++){
                        if($i<=$numpages){
                        ?>
              <a href="#" class='JO_pagesi' onclick="tuyen_du_lieu('<?=$i?>');">
              <?=$i?>
              </a>
              <?
                        }
                    }
                    if($page+4<$numpages) echo "...";
                    if($page<$numpages){
                    ?>
              <a href="#" class='JO_pagesi' onclick="tuyen_du_lieu('<?=($page+1) ?>');">▷</a>
              <?
                    }
                    if($page<($numpages-1)){
                    ?>
              <a href="#" class='JO_pagesi' onclick="tuyen_du_lieu('<?=$numpages ?>');">▶</a>
              <?
                    }

                }
                 ?>
						</td>
                        <td></td>
          
          </tr>
          <?php  }?>
        </table>